#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int N = 1010;
int n,k;
ll a[N];
ll dp[N][N];
int main() {
    cin >> n >> k;
    for(int i=1;i<=n;i++) cin >> a[i];
    memset(dp,-0x3f,sizeof dp);
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<k;j++)
        {
            dp[i][j]=max(dp[i-1][j],dp[i-1][(j-a[i]%k+k)%k]+a[i]);
        }
    }
    if(dp[n][0]<=0) cout << -1 << endl;
    else cout << dp[n][0] << endl;
    return 0;
}